use util::RawData;

use crate::constants::DefaultFingerprintType;

lazy_static!{
	pub static ref CHUNK_LAYOUT_NONE:ChunkLayout = ChunkLayout { kind:ChunkKind::Unique,data_len:0,fp:DefaultFingerprintType::from([0;20]) };
}

#[derive(Clone,Copy,Debug,)]
pub enum ChunkKind {
	Unique,
	Delta,
}

impl ChunkKind {
	pub fn is_unique(&self) -> bool {
		match self {
			Self::Unique => true,
			Self::Delta => false,
		}
	}

	pub fn is_delta(&self) -> bool {
		match self {
			Self::Unique => false,
			Self::Delta => true,
		}
	}
}

#[derive(Clone,Copy,Debug,RawData)]
pub struct ChunkLayout {
	kind:ChunkKind,
	data_len:usize,
	fp:DefaultFingerprintType,
}

impl ChunkLayout {
	#[inline(always)]
	pub fn unique(data_len:usize,fp:DefaultFingerprintType) -> Self {
		Self {
			kind:ChunkKind::Unique,
			data_len:data_len,
			fp:fp,
		}
	}

	#[inline(always)]
	pub fn delta(data_len:usize,fp:DefaultFingerprintType) -> Self {
		Self {
			kind:ChunkKind::Delta,
			data_len:data_len,
			fp:fp,
		}
	}

	pub fn kind(&self) -> ChunkKind {
		self.kind
	}
	
	pub fn data_len(&self) -> usize {
		self.data_len
	}
	
	pub fn set_delta_len(&mut self,delta_len:usize) {
		self.kind = ChunkKind::Delta;
		self.data_len = delta_len;
	}
	
	pub fn fp(&self) -> &DefaultFingerprintType {
		&self.fp
	}

	pub fn is_unique(&self) -> bool {
		if let ChunkKind::Unique = self.kind {
			return true;
		} else {
			return false;
		}
	}
}
